package com.atguigu.crowd.config;

import com.atguigu.crowd.entity.Admin;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.User;

import java.util.Collection;
import java.util.List;

/**
 * 为了能获取到Admin的其他数据，对User类进行扩展
 *
 * @author Chan
 * @since 2022/9/26
 */
public class SecurityAdmin extends User {
    /**
     * 供获取的Admin对象
     */
    private final Admin originalAdmin;

    /**
     * constructor
     * @param originalAdmin 传入的原始Admin对象
     * @param authorities   权限集合
     */
    public SecurityAdmin(Admin originalAdmin, Collection<GrantedAuthority> authorities) {
        super(originalAdmin.getUserName(), originalAdmin.getUserPswd(), authorities);
        this.originalAdmin = originalAdmin;
    }

    public Admin getOriginalAdmin() {
        return originalAdmin;
    }
}
